const app = getApp();
let ServiceUrl = app.globalData.ServiceUrl;
Page({
  data: {
    oldmanInfo: {},
    orderInfo: {},
    userInfo: {},
    order_id:'',
    user_id:'',
    role_state:'',
    src_type:'',
    new_state:'',//步骤active
    steps: [
      {
        desc: '未付款',
      },
      {
        desc: '待派单',
      },
      {
        desc: '已接单',
      },
      {
        desc: '服务中',
      },
      {
        desc: '完成订单',
      },
    ],
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function (options) {
//    wx.stopPullDownRefresh();//刷新完成后停止下拉刷新动效
    console.log(options);
    //参数：order_id  role_state
    let that=this;
    that.setData({
      role_state: options.role_state,
      order_id: options.order_id
    })
    if(wx.getStorageSync('uid') == '' || wx.getStorageSync('uid') == null){
      wx.showModal({
            title: '提示',
            content: '请先登录',
            showCancel: false, //是否显示取消按钮-----》false去掉取消按钮
            confirmColor: 'skyblue', //确定文字的颜色
            success: function(res) {
                if(res.confirm){//点击确定
                    console.log("您点击了确定")
                    wx.redirectTo({
                      url: '../index/index',
                    })
                }
            }
       })
    }else{
      let order_id = options.order_id
      that.request(order_id);
    }
  },
  /**
   * 发送请求获取订单信息
   * @param {*} order_id 
   */
  request:function(order_id){
    let that = this
    //向后台发送请求获得数据
    wx.request({
      url: ServiceUrl + 'getOrderInfoAll',
      data:{order_id: order_id},
      success:function(res){
        console.log(res)
        if(res.data.state == 200){
          if(res.data.orderInfo.src_type == 0){
            var src_type = '微信下单';
          }else{
            var src_type = '后台下单';
          }
          that.setData({
            oldmanInfo: res.data.oldmanInfo,
            orderInfo: res.data.orderInfo,
            userInfo: res.data.userInfo,
            new_state: res.data.orderInfo.new_state,
            src_type: src_type
          })
        }
      },
      fail:function(res){
        wx.showModal({
          title:"提示",
          content:"发送请求失败",
          showCancel:false
        })
      }
    })
  },
/**
 * 前往派单界面
 */
sendOrder:function(){
  let that = this
  console.log(that.data.orderInfo.company_id)
  wx.navigateTo({
    url: '../order/sendOrder?company_id=' + that.data.orderInfo.company_id + '&order_id=' + that.data.orderInfo.order_id,
  })
},

  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function () {
    
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function () {
    
  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function () {
    
  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function () {
    
  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function (options) {
    let that=this;
    //获取订单order_id
    console.log(that.options);
    let order_id = that.data.order_id;
    that.request(order_id);
    setTimeout(() => {
      wx.stopPullDownRefresh();//停止下拉刷新状态
    }, 3000);
  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function () {
    
  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function () {
    
  }
})